package com.wxtwxt.ruralmall.order.interceptor;

import com.wxtwxt.ruralmall.common.vo.MemberVo;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Wxt
 * @create 2023-04-26 21:53
 */
@Component
public class OrderInterceptor implements HandlerInterceptor {
    public static final ThreadLocal<MemberVo> threadLocal = new ThreadLocal<>();
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        MemberVo attribute = (MemberVo) request.getSession().getAttribute("data");
        if(attribute != null) {
            threadLocal.set(attribute);
            return true;
        }else {
            request.getSession().setAttribute("msg", "请先登录");
            response.sendRedirect("http://auth.gulimall.com/login.html");
            return false;
        }
    }
}
